// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   SetGcdByTer.java

package nc.impl.jmcg.traysouce;

import java.util.ArrayList;
import java.util.List;
import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.pub.taskcenter.BgWorkingContext;
import nc.bs.pub.taskcenter.IBackgroundWorkPlugin;
import nc.jdbc.framework.processor.ArrayListProcessor;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.vo.pub.BusinessException;

public class SetGcdByTer
	implements IBackgroundWorkPlugin
{

	BaseDAO dao1;
	BaseDAO dao2;

	public SetGcdByTer()
	{
		dao1 = new BaseDAO("JMMCMDB");
		dao2 = new BaseDAO();
	}

	public String executeTask(BgWorkingContext bgwc)
		throws BusinessException
	{
		List deflist = new ArrayList();
		String sql = "select VIN,CHANGE_TYPE,saleArea,ownerName,Idnum,epname,epaddress,vehTypeName,TC_attribute,pk_dms_tc,epcode,CHANGE_TYPE from T_DMS_TERMINALCLIENT  where nc_read = 0";
		deflist = (List)dao1.executeQuery(sql, new ArrayListProcessor());
		for (int i = 0; i < deflist.size(); i++)
		{
			Object objs[] = (Object[])deflist.get(i);
			String def53=getgcddef53((String)objs[0]);
			if(def53!=null&&def53.equals("Y")&&objs[11]!=null&&objs[11].equals("S")){
				String update = "update jmmc_gcd set def54='Y' where vin='"+objs[0]+"'";
				dao2.executeUpdate(update);
			}else if((def53==null||(def53!=null&&def53.equals("N")))&&objs[11]!=null&&objs[11].equals("S")){
				String update = "update jmmc_gcd set saleArea='',ownerName='',Idnum='',epname='',epaddress='',epcode='',TC_attribute='',vehTypeName='' where vin='"+objs[0]+"'";
				dao2.executeUpdate(update);
			}else{
			String updatemid = (new StringBuilder("update T_DMS_TERMINALCLIENT set nc_read=1 where pk_dms_tc='")).append(objs[9]).append("'").toString();
			String update = (new StringBuilder("update jmmc_gcd set saleArea='")).append(objs[2]).append("',ownerName='").append(objs[3]).append("',Idnum='").append(objs[4]).append("',epname='").append(objs[5]).append("',").append("epaddress='").append(objs[6]).append("',epcode='").append(objs[10]).append("',TC_attribute='").append(objs[8]).append("',vehTypeName='").append(objs[7]).append("' where vin='").append(objs[0]).append("'").toString();
			dao2.executeUpdate(update);
			dao1.executeUpdate(updatemid);}
		}

		return null;
	}
	public String getgcddef53(String vin){
		String sql = "select def53 from jmmc_gcd where vin='"+vin+"'";
		String def53 = "";
		try {
			def53 = (String) dao2.executeQuery(sql, new ColumnProcessor());
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return def53;
	}
}
